s1_read_last_two_bytes_of_a_mbr_backup_file(){ 
# 检查参数数量  
if [ "$#" -ne 1 ]; then  
    echo "Usage: $0 <MBR_backup_file_path>"  
    exit 1  
fi  
  
# 检查文件是否存在并且可读  
if [ ! -f "$1" ] || [ ! -r "$1" ]; then  
    echo "Error: File $1 does not exist or is not readable."  
    exit 1  
fi  
# 获取文件的最后两个字节并检查是否为55, AA  
last_two_bytes=$(tail -c 2 "$1")  
if [ "$last_two_bytes" = "55AA" ]; then  
    echo "YES"  
else  
    echo "NO"  
Fi
 } 
s2_read_mbr_partition_table_info() {
    local mbr_file=$1
    for i in {0..3}; do
        local offset=$((0x1be + i * 16))
        local entry=$(dd if="$mbr_file" bs=1 skip=$offset count=16 2>/dev/null | xxd -p -c 16)
        local start_sector=$(echo "ibase=16; $(echo $entry | cut -c9-16 | tac -rs ..)" | bc)
        local end_sector=$(echo "ibase=16; $(echo $entry | cut -c25-32 | tac -rs ..)" | bc)
        local sectors=$(echo "ibase=16; $(echo $entry | cut -c33-40 | tac -rs ..)" | bc)
        if [ $sectors -gt 0 ]; then
            local end_sector=$((start_sector + sectors - 1))
            echo "$start_sector $end_sector"
        fi
    done
}
s3_parse_partition_info() {
    while read -r line; do
        case "$line" in
            *bytes*)
                if [[ "$line" =~ ([0-9]+) bytes ]]; then
                    echo "disk size in bytes:${BASH_REMATCH[1]}"
                elif [[ "$line" =~ ([0-9]+) sectors ]]; then
                    echo "disk size in sectors:${BASH_REMATCH[1]}"
                elif [[ "$line" =~ physical.*([0-9]+) bytes ]]; then
                    echo "physical sector size in bytes:${BASH_REMATCH[1]}"
                fi
                ;;
            /dev/vda1*)
                IFS=' ' read -ra ADDR <<< "$line"
                echo "first partition start sector id:${ADDR[1]}"
                echo "first partition end sector id:${ADDR[2]}"
                echo "first partition type:${ADDR[5]}"
                ;;
        esac
    done
}
s4_run_passwd_as_plain_user_and_get_status() {
    local oversleeping_path=$(which oversleeping)
    sudo chown root $oversleeping_path
    sudo chmod 4755 $oversleeping_path
    $oversleeping_path &
    sleep 1 # Wait for the process to start
    local pid=$(pgrep -f oversleeping)
    local process_info=$(ps -o uid,euid,ruid -p $pid)
    local uids=$(echo $process_info | awk 'NR==2 {print $1","$2","$3}')
    local usernames=$(getent passwd $(echo $uids | tr ',' ' ') | cut -d: -f1 | tr '\n' ',')
    usernames=${usernames::-1} # Remove trailing comma
    echo "$uids"
    echo "$usernames"
}
s5_add_a_scheduled_task() {
    (crontab -l 2>/dev/null; echo "*/5 * * * * date '+\%Y\%m\%d_\%H\%M\%S' >> $HOME/test_crontab") | crontab -
}
